Skip to content

Instantly share code, notes, and snippets.

@lazee
Created August 18, 2015 19:28
Show Gist options
  • Save lazee/f5c524b3c7bebf68955e to your computer and use it in GitHub Desktop.
Save lazee/f5c524b3c7bebf68955e to your computer and use it in GitHub Desktop.
UriDecodeDirective test class
import freemarker.Java8ObjectWrapper;
import freemarker.UriDecodeDirective;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
public class Tester {
public static void main(String[] args) throws IOException, TemplateException {
Configuration configuration = new Configuration();
configuration.setObjectWrapper(new Java8ObjectWrapper(Configuration.VERSION_2_3_23));
configuration.setSharedVariable("decode", new UriDecodeDirective());
System.out.println(
process("<@decode>hello+world%3F</@decode>", configuration)
);
}
public static String process(String templateString, Configuration configuration)
throws IOException, TemplateException {
Template t = new Template("name", new StringReader(templateString), configuration);
Writer out = new StringWriter();
t.process(new HashMap<String, Object>(), out);
out.flush();
return out.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment